package org.mq.mymq.broker.model;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName QueueModel
 * @Description 队列配置信息映射对象
 * @Author jiarong_ye
 * @Date 2025/6/15 17:44
 * @Version 1.0
 */
public class QueueModel {
    /**
     * 队列ID
     */
    private Integer id;
    /**
     * 队列的名称
     */
    private String fileName;
    /**
     * 当前队列最大容量
     */
    private Integer offsetLimit;
    /**
     * 当前队列读取消息位置
     */
    private AtomicInteger latestOffset;
    /**
     * 当前队列已读取但未删除的最早消息位置
     */
    private Integer lastOffset;

    @Override
    public String toString() {
        return "QueueModel{" +
                "id=" + id +
                ", fileName='" + fileName + '\'' +
                ", offsetLimit=" + offsetLimit +
                ", latestOffset=" + latestOffset +
                ", lastOffset=" + lastOffset +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public Integer getOffsetLimit() {
        return offsetLimit;
    }

    public void setOffsetLimit(Integer offsetLimit) {
        this.offsetLimit = offsetLimit;
    }

    public AtomicInteger getLatestOffset() {
        return latestOffset;
    }

    public void setLatestOffset(AtomicInteger latestOffset) {
        this.latestOffset = latestOffset;
    }

    public Integer getLastOffset() {
        return lastOffset;
    }

    public void setLastOffset(Integer lastOffset) {
        this.lastOffset = lastOffset;
    }

    public int countDiff() {
        return this.offsetLimit - this.latestOffset.get();
    }
}
